<template>
    <div>
        <!-- mui 下的 tab-top-webview-main -->
		<!-- 滑动导航 -->
       <div class="mui-content">
			<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<!-- tap 的作用跟 click 类似， 但 tap 只能用在 mui 中 -->
						<a @tap="getNewlist(item.id)" :class="['mui-control-item',item.id==0?'mui-active':'']" data-wid="tab-top-subpage-1.html" v-for="item in cates" :key="item.id">
							{{ item.title }}
						</a>
					</div>
				</div>

			</div>
		</div>	

		<!-- 图片内容区 -->
		<ul class="photo-list">
			<!-- tag="li" 的作用，让router-link 渲染的标签为li,即在浏览器查看代码时看到的是 li 标签 -->
  			<router-link :to="'/home/photolist/photoInfo/'+item.id" v-for="item in list" :key="item.id" tag="li">
    			<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{ item.title }}</h1>
					<div class="info-body">{{ item.zhaiyao }}</div>
				</div>
			</router-link> 
		</ul>
    </div>
</template>

<script>
// 使用导入以下 mui 需要移除严格模式
// 安装方法：npm install babel-plugin-transform-remove-strict-mode -D
// 在 .babelrc 中添加以下内容： "plugins": ["transform-remove-strict-mode"]
import mui from '../../lib/mui/js/mui.js';
export default {
	data() {
		return {
			cates:[],
			list:null,

		}
	},
	created() {
		this.getNavList();
		this.getNewlist(0);
	},
	methods: {
		//从后台获取 导航栏列表
		getNavList(){
			this.$http.get("photocates.json").then(result => {
				this.cates = result.body;
			})
		},
		getNewlist(id){
			this.$http.get('photos.json').then(result => {
				if(id == 0){
					this.list = result.body;
				}else{
					this.list = result.body.filter(item => {
						if(item.cateid == id){
							return item;
						}
					})
				}
			})
		}
	},
	mounted() { // 页面加载好之后执行的钩子函数
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
	},
}
</script>



<style lang="scss" scoped>
/* 解决警告加以下样式[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See <URL> */
	/* 是chrom 为了提高滑动流畅度 */
	* { touch-action: pan-y; }
	.photo-list{
		list-style: none;
		margin: 0;
		padding: 10px;
		padding-bottom: 0;

		li{
			background-color: #ccc;
			text-align: center;
			margin-bottom: 10px;
			box-shadow: 0 0 9px #999;
			position: relative;
			
			img{
				width: 100%;
				height: 300px;
			}

			image[lazy=loading] {
				width: 40px;
				height: 300px;
				margin: auto;
			}

			 .info {
				 width: 100%;
				color: white;
				text-align: left;
				position: absolute;
				bottom: 0;
				background-color: rgba(0, 0, 0, 0.4);
				max-height: 84px;
				.info-title {
					font-size: 14px;
				}
				.info-body {
					font-size: 13px;
				}
			 }
		}

	}
</style>